<div class="modal-body">
	<form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="id" id="projectId">
		<input type="hidden" name="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<div class="box-body">
			<div class="col-md-6">
				<div class="form-group">
					<label for="no" class="col-sm-3 control-label">项目编号</label>

					<div class="col-sm-8">
						<input type="text" class="form-control" id="no" name="no" placeholder="项目编号">
					</div>
				</div>
				<div class="form-group">
					<label for="location" class="col-sm-3 control-label">项目位置</label>

					<div class="col-sm-8">
						<input type="text" class="form-control" id="location" name="location" placeholder="项目位置">
					</div>
				</div>
				<div class="form-group">
					<label for="province" class="col-sm-3 control-label">管辖区域</label>
					<div class="col-sm-8">
							<select id="province" class="form-control" name="province"
									onchange="chooseArea('city', this.options[this.options.selectedIndex].value);">
								<option value="" label="请选择省份"/>
							</select>
							<select id="city" class="form-control" name="city" style="margin-top:6px;"
									onchange="chooseArea('area', this.options[this.options.selectedIndex].value);">
								<option>请选择城市</option>
							</select>
							<select id="area" class="form-control" name="areaCode" style="margin-top:6px;">
								<option>请选择区域</option>
							</select>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<label for="name" class="col-sm-3 control-label">项目名称</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="name" name="name" placeholder="项目名称">
					</div>
				</div>
				<div class="form-group">
					<label for="recordNo" class="col-sm-3 control-label">备案编号</label>

					<div class="col-sm-8">
						<input type="text" class="form-control" id="record_no" name="recordNo" placeholder="备案编号">
					</div>
				</div>
				<div class="form-group">
					<label for="description" class="col-sm-3 control-label">描述信息</label>
					<div class="col-sm-8">
						<textarea rows="5" class="form-control" id="description" name="description" placeholder="描述信息"/>
					</div>
				</div>
			</div>
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button type="button" class="btn btn-primary" data-btn-type="save" onclick="save_project()">提交</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		initArea( "province", "0" );
	});
	
	function chooseArea( type, code ){
		if( "city" == type ){
			$( "#city" ).empty();
			$( "#city" ).append("<option>请选择城市</option>");
			initArea( "city", code );
		}else if( "area" == type ){
			$( "#area" ).empty();
			$( "#area" ).append("<option>请选择地区</option>");
			initArea( "area", code );
		}
	}
	
	function initArea( sel_id, parent_code, fn ){
		var url = "../../tbl_area/list";
		var paramMap = {};
		paramMap.parent_code = parent_code;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
						$( "#" + sel_id ).append("<option value='"+ this.area_code +"'>"+ this.area_name +"</option>");
				  });
				  if( fn ){
					  fn();
				  }
			  }
		});
	}
	
	function save_project( fn ){
		var project = {};
		project.id = $("#id").val();
		project.name = $("#name").val();
		project.no = $("#no").val();
		project.location = $("#location").val();
		project.province_code = $("#province").val();
		project.city_code = $("#city").val();
		project.area_code = $("#area").val();
		project.record_no = $("#record_no").val();
		project.description = $("#description").val();
		var json_data = JSON.stringify( project );
		var url = "../../tbl_project/save";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert( json.message );
				 $("#project_main").load("devicedata/devicedata_list.html");
				 dialog_close();
			  }
		});
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>